package jee.boot.entity.system;

import jee.boot.common.annotation.Column;
import jee.boot.common.annotation.Table;
import jee.boot.common.basic.TreeEntity;

/**
 * 行政区划Entity
 *
 * @author zhilei.wang
 * @version 2018-09-28
 */
@Table(name="st_area")
public class Area extends TreeEntity<Area> {

    private static final long serialVersionUID = 1L;
    @Column(name = "parent_id", data = {"parent.id", "parent.name"})
    private Area parent;
    private String code; // 区域编码
    private String type; // 区域类型
    @Column(ignoreAlias = true, name = "(select count(1) from st_area child where child.parent_id=a.id)", action = Column.Action.QUERY)
    private Integer childNum = 0;
    @Column(ignoreAlias = true, name = "(select ifnull(max(child.level)-a.level,0) from st_area child where child.parent_ids like  CONCAT('%',a.id,',%'))", action = Column.Action.QUERY)
    private Integer childDeep = 0;
    public Area() {
        super();
        setTenantModule(false);
        setCacheKey(getProjectConfig().getName() + "_areaCache");
    }

    public Area(String id) {
        super(id);
        setTenantModule(false);
        setCacheKey(getProjectConfig().getName() + "_areaCache");
    }

    public Area getParent() {
        return parent;
    }

    public void setParent(Area parent) {
        this.parent = parent;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getChildNum() {
        return childNum;
    }

    public void setChildNum(Integer childNum) {
        this.childNum = childNum;
    }

    public Integer getChildDeep() {
        return childDeep;
    }

    public void setChildDeep(Integer childDeep) {
        this.childDeep = childDeep;
    }

    public static void main(String[] args) {
        System.out.println(new Area().getGetSql());
    }
}